package com.sgd;

public class ThreadTest extends Thread{
    private String name;

    /**
     * 线程名称
     * @param name
     */
    public ThreadTest(String name) {
        this.name = name;
    }

    /**
     * 要执行的任务
     */
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(name + "运行了" + i);
            try {
                sleep((long) (Math.random()*10));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        ThreadTest a = new ThreadTest("a");
        ThreadTest b = new ThreadTest("b");
        a.start();
        b.start();
    }
}
